<template name="confirmGood">
	<view class="goodRow">
		<view class="goodInfo">
			
			<view class="infoBox">
				<image :src="goodInfo.img"></image>
				<view class="textBox">
					<text class="title">{{goodInfo.name?goodInfo.name:goodInfo.courseName}}</text>
					<text class="price">￥{{goodInfo.price.toFixed(2)}}</text>
				</view>
			</view>
		</view>
		<view class="numAndPrice">
			<view class="priceBox">
				<text>预约金小计：￥{{(goodInfo.prepay).toFixed(2)}}</text>
				
				<text v-if="!coupon">尾款小计：￥{{(goodInfo.price-goodInfo.prepay).toFixed(2)}}</text>
				<text v-if="coupon">尾款小计：￥{{(goodInfo.price-goodInfo.prepay-coupon.coupon.discount).toFixed(2)}}</text>
			</view>
			
			<!-- <view class="jishuBox">
				<button @tap="reduce" :disabled="goodInfo.num<=1">-</button>
				<input type="number" class="goodNum" v-model="goodNum" @blur="inputBlur" />
				<button @tap="add">+</button>
			</view> -->
		</view>
		
		<view class="couponRow" @tap="toggleCoupon" v-if="cpList.length>0">
			<view class="couponTicket" >
				<view class="leftCircle"></view>
				<text>牛牛券</text>
				<view class="rightCircle"></view>
			</view>
			<text class="couponValue" :class="coupon?'':'noselect'">{{coupon?('-￥'+coupon.coupon.discount):'点击选择优惠券'}}</text>
			<text class="iconfont icon-right"></text>
		</view>
	</view>
</template>

<script>
	// vuex 导入
	import {
		mapState,
		mapGetters,
		mapMutation,
		mapActions
	} from "vuex";
	export default {
		computed: {
			...mapState({
				userInfo: state => state.user.userInfo
			})
		},
		name: 'confirmGood',
		// 传递参数
		props: {
			goodInfo:{
				type:Object,
				default:function(){
					return {
						goodSelect:false,
						name:'课程名称',
						price:0,
						prepay:0,
						courseName:'课程名称',
						img:'../../static/loding.png'
					}
				}
			},
			coupon:{
				type:Object,
				default:null
			},
			cpList:{
				type:Array,
				default:()=>{
					return []
				}
			}
		},
		// 自身参数
		data() {
			return {
				goodNum:1,
				typeArr:['','牛牛券','优惠券']
			}
		},
		// 方法
		methods: {

			methods1() {

				// this.$store.dispatch("someText", payload); //调用dispatch
				// this.commit("someText", payload); //调用commit

			},
			reduce(){
				if(this.goodNum>1){
					this.goodNum=parseInt(this.goodNum)-1
				}else{
					
				}
			},
			add(){
				
				this.goodNum=parseInt(this.goodNum)+1
				
			},
			inputBlur(){
				// this.$store.dispatch("apiUpdateNum",{
				// 	id:this.goodInfo.id,
				// 	num:(this.goodNum)
				// }).then(res=>{
				// 	this.goodNum=parseInt(this.goodNum)
				// })
			},
			toggleCoupon(){
				this.$root.toggleCoupon();
			}
		},
		watch:{
			goodNum(newNum){
				uni.$emit("getPrice",{count:newNum})
			}
		},
		// created声明周期
		created() {
			this.goodNum=parseInt(this.goodInfo.num);
		},

	}
</script>

<style lang="less" scoped>
	
	.couponTicket{
		margin-left: 0;
	}
	.goodRow {
		display: flex;
		flex-direction: column;
		padding: 28upx 18upx 28upx 40upx;

		.goodInfo {
			display: flex;
			align-items: center;

			.selectGoog {
				font-size: 44upx;
				margin-right: 40upx;
				color: rgba(0,0,0,0);
			}

			image {
				width: 160upx;
				height: 160upx;
				border-radius: 10upx;
				margin-right: 18upx;
			}

			.infoBox {
				flex: 1;
				display: flex;
				image{
					flex-shrink: 0;
				}
				.textBox {
					display: flex;
					flex-direction: column;

					.title {
						font-size: 30rpx;
						color: #202932;
						margin-bottom: 30upx;
					}

					.price {
						font-size: 36rpx;
						font-weight: bold;
						color: #ff3b2b;
					}
				}
			}
		}
		.couponRow{
			display: flex;
			margin-top: 50upx;
			font-size: 32upx;
			align-items: center;
			color: #939393;
			.couponValue{
				color: #fe1739;
				flex-grow: 1;
				text-align: right;
				font-weight: bold;
				margin-right: 20upx;
			}
			.noselect{
				font-weight: normal;
				color: #CCCCCC;
			}
		}
		.numAndPrice {
			display: flex;
			align-items: flex-end;
			margin-top: 40upx;

			.iconfont {
				font-size: 44upx;
				margin-right: 40upx;
				color: rgba(0, 0, 0, 0);
			}

			.priceBox {
				display: flex;
				flex-direction: column;
				flex-shrink: 0;
				flex-grow: 1;
				text {
					font-size: 26rpx;
					color: #202932;
				}

				text:last-child {
					font-size: 26rpx;
					color: #939393;
					margin-top: 20upx;
				}
			}
			.jishuBox{
				display: flex;
				height: 54upx;
				border: 1px solid #e5e5e5;
				border-radius: 10upx;
				overflow: hidden;
				button{
					border: none;
					line-height: 50upx;
					height: 50upx;
					padding: 0;
					text-align: center;
					width: 52upx;
					font-size: 32upx;
					border-radius: 0;
					background-color: rgba(0,0,0,0);
					color: #b9b9b9;
				}
				button:after{
					border: none;
					outline: none;
					border-radius: 0;
				}
				button:first-of-type{
					border-right: 1px solid #e5e5e5;
				}
				button:last-of-type{
					border-left: 1px solid #e5e5e5;
					
				}
				.goodNum{
					width: 80upx;
					background-color: rgba(0,0,0,0);
					color: #737373;
					text-align: center;
					font-size: 24upx;
					line-height: 50upx;
					height: 50upx;
				}
			}
		}
	}
</style>
